package com.leo.stockmarket.controller;

import com.alibaba.fastjson.JSONObject;
import com.leo.stockmarket.bean.Article;
import com.leo.stockmarket.service.ArticleService;
import com.leo.stockmarket.util.PageRequest;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 890231 lxj
 * @version 1.0
 * @date 2020/8/20 17:08
 */
@RestController
@RequestMapping(value = "/article")
public class ArticleController {

    @Autowired
    ArticleService articleService;

    @RequestMapping(value = "/hello")
    public String index() {
        return "hello world";
    }

    @RequestMapping(value="/getList")
    public Object getList(@RequestBody PageRequest page) {
        return articleService.queryPage(page);
    }

    @RequestMapping({"/getDetail"})
    public JSONObject getDetail(@Param("businessId")String businessId) throws Exception {
        Article bean = articleService.queryById(businessId);
        Map<String, Object> result = new HashMap();
        result.put("bean", bean);
        return (JSONObject) JSONObject.toJSON(result);
    }
}
